import { refreshToken } from "@/api/modules/login";
import { PublicStore } from "@/stores/modules/public";
import { dayjs } from "element-plus";
const appRefreshToken = () => {
	let doc = document.getElementById("app");
	const publicStore = PublicStore();
	doc &&
		doc.addEventListener("click", async () => {
			let diff = dayjs().diff(dayjs(publicStore.expire), "minute");
			if (0 > diff && diff > -15 && publicStore.token) {
				const { result } = await refreshToken();
				publicStore.setToken(result.token);
				publicStore.setExpire(result.expire);
			}
		});
};
export default appRefreshToken;
